<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <title>填写推荐码</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../css/common.css" />
    <style>
        .single_input{background: #f5f5f5;border-radius: 2px;}
        .single_input input{padding-left: .5rem;}
    </style>
</head>
<body>
	<header class="aui-bar aui-bar-nav jb" id="header">
	    <a class="aui-pull-left aui-btn" onclick="cancel();">
	        <span class="aui-iconfont aui-icon-left"></span>&nbsp;&nbsp;取消
	    </a>
	    <div class="aui-title" id="title">填写推荐码</div>
	</header>
     <section class="aui-content aui-padded-10 bg-white">
     	 <div class="single_input aui-margin-b-15">
     	 	<input type="text" name="" placeholder="请输入推荐码" id="invite_code">
     	 </div>
     	 <div class="aui-btn aui-btn-danger aui-btn-block jb" onclick="find()">确定</div>
     </section>
     
</body>
<script type="text/javascript" src="../script/api.js" ></script>
<script type="text/javascript" src="../script/zepto.min.js" ></script>
<script type="text/javascript" src="../script/common.js" ></script>
<script type="text/javascript">
    var wxinfo;
    apiready = function(){
        api.parseTapmode();
        var header = $api.byId('header');
        $api.fixStatusBar(header);
        api.addEventListener(
        	{
                name: 'keyback'
            }, function (ret, err) {
            	cancel();
            }
	    )
        wxinfo = api.pageParam.wxinfo;
    };
    function find(){
    	var invite_code = $('#invite_code').val();
    	if (invite_code=='') {
    		_toast('请填写推荐码');
    		return false;
    	}
        wxinfo.invite_code = invite_code;
    	_loading('激活中','',true);
    	_Ajax(window.APIServer.WxLogin,'post',{values:wxinfo},'json',function(ret){
    		_loading_close();
    		_toast(ret.msg);
    		if (ret.code==1) {
                var uinfo = ret.data;
                //存储用户信息
                _SetPrefs('token', uinfo.token);
                _SetPrefs('uid', uinfo.uid);
                _SetPrefs('uinfo', uinfo);
                //_SetPrefs('face', uinfo.face);//暂时不用头像
                //广播事件：用户登录成功
                _SendEvent('UserLogin', uinfo.uid);
                setTimeout(function() {
                     api.closeToWin({
                         name : 'root'
                     });
                }, 500)
    		}
    	});
    }
    //退出登录
    function cancel() {
        setTimeout(function() {
            _RemovePrefs('uid');
            _RemovePrefs('token');
            _RemovePrefs('uinfo');
            api.closeToWin({
			    name: 'root'
			});
            //广播事件：退出登录
            _SendEvent('UserLogout');
        }, 100)
    };
</script>
</html>